<html>
<head><title>PHP test v1</title></head>
<body>
<h3>求两个日期的差数：2007-2-5~2007-3-6</h3>
<?
$time1=mktime(0,0,0,2,5,2007);
$time2=mktime(0,0,0,3,6,2007);
echo "相差天数为".(($time2-$time1)/3600/24)."<br />";
echo "相差小时为".(($time2-$time1)/3600)."<br />";
echo "相差分钟为".(($time2-$time1)/60)."<br />";
echo "相差秒为".($time2-$time1)."<br />";
?>
<h3>请写一个函数，实现以下功能：<br />字符串"open_door"转换为"OpenDoor"、"make_by_id"转化为"MakeById"</h3>
<?
function newstr($str){
	$newstr=str_replace(" ","",ucwords(str_replace("_"," ",$str)));
	return $newstr;
	}
echo newstr("open_door")."<br />";
echo newstr("make_by_id")."<br />";

function newstr2($str){
	$str1=explode("_",$str);
	$str2="";
	foreach($str1 as $v){
		$str2.=ucwords($v);
		}
	return $str2;
	}
echo newstr2("open_door")."<br />";
echo newstr2("make_by_id")."<br />";
?>
<h3>写一种验证139开头的11位手机号码的正则表达式</h3>
<?
$reg1="/^139[0-9]{8}$/";
$reg2="139553556666";
echo $reg2;
echo (preg_match($reg1,$reg2)?"符合":"不符合");
?>

<h3>请写一个函数将123456789转换成123，456，789</h3>
<?
function numformate($num){
	$str=(string)$num;
	$str2=strrev($str);
	$str3="";
	for($i=0;$i<strlen($str2);$i=$i+3){
		$str3.=substr($str2,$i,3).',';
		}
	$str4=strrev(rtrim($str3,','));
	return $str4;
	}
echo "123456789转换成了".numformate(123456789);

echo "或者利用系统函数也可以得出结论".number_format(123456789,0,'.',',');
?>

<h3>读取网站www.baidu.com的内容并存入字符串</h3>
<?
$str=file_get_contents("http://baidu.com");
echo "要将php.ini中的allow_url_fopen设置成On";
//echo $str;
?>

<h3>将上面的解析到的html内容中的title值解析出来!</h3>
<?
$str2="999<title>123</title>999";
echo $str2;
$reg='/<title>(.*?)<\/title>/';
$reg2='/999(.*?)999/';
preg_match($reg,$str2,$m);
var_dump($m);
?>

























</body>

</html>